package com.abigdreamer.wordpress;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**   
 * 
 * @author Darkness
 * @date 2013-2-6 下午07:59:37
 * @website http://www.abigdreamer.com 
 * @version V1.0   
 */
public class WebGather {
	
	public void gather(String website, String url) {
		String content = "";
		try {
			content = gatherHtml(url);
		} catch (Exception e) {
			e.printStackTrace();
		}
		//writeIntoFile(website, content);
	}
	
	

	public  String gatherHtml(String _url) throws Exception {
		//http://meiwen.pw/?p=803
		
		URL url = new URL(_url);
		HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
		InputStreamReader input = new InputStreamReader(httpConn.getInputStream(), "utf-8");
		BufferedReader bufReader = new BufferedReader(input);
		String line = "";
		StringBuilder contentBuf = new StringBuilder();
		while ((line = bufReader.readLine()) != null) {
			contentBuf.append(line);
			contentBuf.append("\n");
		}
		return contentBuf.toString();
	}
}
